package main

import (
	"fmt"
	"time"
)

func main() {

	//c := make(chan int)
	//defer close(c)
	//go func() {
	//	defer fmt.Println("done")
	//	fmt.Println("go ing")
	//	c<- 666
	//}()
	//i := <-c
	//fmt.Println(i)

	//go func() {
	//	for i := 0; i < 5; i++ {
	//		c<- i
	//	}
	//	close(c)
	//}()
	//
	//time.Sleep(time.Second)
	//
	//for i := range c {
	//	fmt.Println(i)
	//}
	//
	//for {
	//	select {
	//	case <-c:
	//		fmt.Println("c取出")
		//case c<-:
		//	fmt.Println("c写入")
	//	}
	//}

	//c := make(chan int)
	//q := make(chan int)
	//
	//go func() {
	//	for i := 0; i < 5; i++ {
	//		fmt.Println(<-c)
	//	}
	//	q<- 0
	//}()
	//
	//feibo(c,q)



	ch1 := make(chan int)
	ch2 := make(chan int)

	go func() {
		time.Sleep(time.Second)
		ch1 <- 1
	}()

	go func() {
		time.Sleep(time.Second * 2)
		ch2 <- 2
	}()

	select {
	case <-ch1:
		fmt.Println("Received from channel 1")
	case <-ch2:
		fmt.Println("Received from channel 2")
	case <-time.After(time.Second * 3):
		fmt.Println("Timeout")
	}
}

func feibo(c, q chan int) {
	x, y := 1, 1

	for {
		select {
		case c<- x:
			x = y
			y = x + y
		case <-q:
			fmt.Println("quit")
			return
		}
	}
}